package com.autoTools.view;

import java.util.HashMap;
import java.util.Map;

import com.autoTools.util.Constants;

public class ShareViewList
{
	private static ShareViewList viewList = null;
	private static Map<String, BaseView> ViewsMap = null;
	private static int idTree = 0;
	public static ShareViewList getInstance(){
		if(viewList == null)
			viewList = new ShareViewList();
		return viewList;
	}
	
	public ShareViewList(){
		ViewsMap = new HashMap<String, BaseView>();
	}
	
	public void putView(BaseView view){
		if(ViewsMap != null && view != null){
			String id = null;
			if(view.getProperty().get(Constants.ID) != null){
				id = view.getProperty().get(Constants.ID);
			}else{
				id = getDefaultId()+"";
			}
			ViewsMap.put(id,view);
		}
	}
	
	public BaseView getView(String id){
		if(ViewsMap != null && id != null){
			return ViewsMap.get(id);
		}
		return null;
	}
	
	public int getDefaultId(){
		while (ViewsMap.get(idTree+"") != null) {
			idTree++;
		}
		return idTree;
	}
}
